import { Nodes } from '@knno/dom';
import {
	PickGroup,
	PickOptions,
	PickValue,
	PickValueFunc,
	PickerEventMap,
	PickUpdateOption,
	Picker as UIPicker,
} from '../components/picker/picker';
import { JSXProps } from '@knno/dom/jsx';
import { AttrCheck, On, isArray, isNumber, jsxBuild } from './utils';

export { UIPicker, PickValue, PickValueFunc, PickUpdateOption };

interface PickerProps extends JSXProps<UIPicker>, On<PickerEventMap, UIPicker> {
	optionGroups?: PickGroup[];
	options?: PickOptions[];
	value?: PickValue[][];
	activeGroup?: number;
}

const ATTRS: AttrCheck = {
	optionGroups: isArray,
	options: isArray,
	value: isArray,
	activeGroup: isNumber,
};

export function Picker(props: PickerProps, children: Nodes[]): UIPicker {
	return jsxBuild(new UIPicker(), props, children, ATTRS);
}
